package tagcloud.gui;

import java.awt.GridBagLayout;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.ImageIcon;
import java.awt.Insets;
import java.awt.event.ActionListener;

import javax.swing.JButton;

public class ErrorPanel extends JPanel {

	private static final long serialVersionUID = 1L;
	private JLabel nameLabel = null;
	private JLabel imageLabel = null;
	private JLabel messageLabel = null;
	private JButton okButton = null;
	private ActionListener parentActionListener;
	
	private String returnCardName;
	
	/**
	 * This is the default constructor
	 */
	public ErrorPanel(ActionListener parentActionListener) {
		super();
		this.parentActionListener = parentActionListener;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
		gridBagConstraints6.gridx = 1;
		gridBagConstraints6.anchor = GridBagConstraints.EAST;
		gridBagConstraints6.gridy = 2;
		GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
		gridBagConstraints2.gridx = 1;
		gridBagConstraints2.fill = GridBagConstraints.BOTH;
		gridBagConstraints2.ipadx = 0;
		gridBagConstraints2.insets = new Insets(0, 10, 0, 0);
		gridBagConstraints2.gridy = 1;
		messageLabel = new JLabel();
		messageLabel.setText("ERROR MESSAGE");
		GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
		gridBagConstraints1.gridx = 0;
		gridBagConstraints1.gridheight = 2;
		gridBagConstraints1.gridy = 0;
		imageLabel = new JLabel();
		imageLabel.setText("");
		imageLabel.setIcon(new ImageIcon(getClass().getResource("/images/error.png")));
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 1;
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints.weightx = 1.0D;
		gridBagConstraints.gridwidth = 1;
		gridBagConstraints.gridy = 0;
		nameLabel = new JLabel();
		nameLabel.setText("ERROR NAME");
		this.setSize(640, 480);
		this.setLayout(new GridBagLayout());
		this.setBorder(BorderFactory.createEmptyBorder(0, 128, 0, 128));
		this.setName("Error Panel");
		this.add(nameLabel, gridBagConstraints);
		this.add(imageLabel, gridBagConstraints1);
		this.add(messageLabel, gridBagConstraints2);
		this.add(getOkButton(), gridBagConstraints6);
	}

	/**
	 * This method initializes okButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	protected JButton getOkButton() {
		if (okButton == null) {
			okButton = new JButton();
			okButton.setText("Ok");
			okButton.addActionListener(parentActionListener);
		}
		return okButton;
	}
	
	public void setReturnCardName(String name) {
		returnCardName = name;
	}
	
	public String getReturnCardName() {
		return returnCardName;
	}
	
	public void setError(String name, String message) {
		nameLabel.setText(name);
		messageLabel.setText("<HTML>" + message + "</HTML>");
	}

}
